package com.fq.myapplication.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.fq.myapplication.R;
import com.fq.myapplication.adapter.SettingsAdapter;
import com.fq.myapplication.bean.SettingItem;
import com.fq.myapplication.utils.ThemeManager;

import java.util.ArrayList;
import java.util.List;

import android.widget.Switch;
import androidx.appcompat.app.AppCompatDelegate;

public class SettingsActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private SettingsAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        // 加载夜间模式设置
        int themeMode = ThemeManager.getThemeMode(this);
        updateTheme(themeMode);

        // 0 初始化
        recyclerView = findViewById(R.id.settings_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        // 1 数据源
        List<SettingItem> items = new ArrayList<>();

        items.add(new SettingItem(SettingItem.TYPE_GROUP_TITLE, "账号", null, null, false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "账号与安全", R.drawable.ic_account, null, false));

        items.add(new SettingItem(SettingItem.TYPE_GROUP_TITLE, "隐私", null, null, false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "隐私设置", R.drawable.ic_privacy, null, false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "推送设置", R.drawable.ic_push, null, false));

        items.add(new SettingItem(SettingItem.TYPE_GROUP_TITLE, "功能设置", null, null, false));
        items.add(new SettingItem(SettingItem.TYPE_SWITCH, "内容自动刷新", R.drawable.ic_refresh, null, true));

        items.add(new SettingItem(SettingItem.TYPE_SWITCH, "展示右下角刷新按钮", R.drawable.ic_corner, null, true));
        items.add(new SettingItem(SettingItem.TYPE_SWITCH, "保存视频带神弹幕", R.drawable.ic_danmaku, null, true));
        items.add(new SettingItem(SettingItem.TYPE_SWITCH, "自动唤起声音电台", R.drawable.ic_radio, null, true));
        items.add(new SettingItem(SettingItem.TYPE_SWITCH, "LIVE实况图展示振动效果", R.drawable.ic_vibration, null, true));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "开屏画面设置", R.drawable.ic_splash, null, false));

        items.add(new SettingItem(SettingItem.TYPE_GROUP_TITLE, "内容设置", null, null, false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "推荐中屏蔽的内容", R.drawable.ic_block, "去修改", false));
        items.add(new SettingItem(SettingItem.TYPE_SWITCH, "夜间模式", R.drawable.ic_night, null, themeMode == AppCompatDelegate.MODE_NIGHT_YES));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "青少年模式", R.drawable.ic_teen, "去开启", false));

        items.add(new SettingItem(SettingItem.TYPE_GROUP_TITLE, "关于", null, null, false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "清除缓存", R.drawable.ic_cache, "7.51MB", false));
        items.add(new SettingItem(SettingItem.TYPE_SWITCH, "内测版本优先体验", R.drawable.ic_beta, null, false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "检查更新", R.drawable.ic_update, "6.3.20 NEW!", false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "个人信息管理", R.drawable.ic_info, null, false));
        items.add(new SettingItem(SettingItem.TYPE_NORMAL, "关于最右", R.drawable.ic_about, null, false));

        items.add(new SettingItem(SettingItem.TYPE_BUTTON, "切换账号", null, null, false));
        items.add(new SettingItem(SettingItem.TYPE_BUTTON, "退出登录", null, null, false));

        // 2 适配器、绑定
        adapter = new SettingsAdapter(items);
        recyclerView.setAdapter(adapter);
    }
    public void updateTheme(int themeMode) {
        AppCompatDelegate.setDefaultNightMode(themeMode);
        recreate(); // 重启Activity以应用新主题
    }
}
